'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Imports System

Imports Microsoft.VisualStudio.TestTools.UnitTesting

Imports JCsTools.Xml.Formatter



'''<summary>
'''This is a test class for DefaultValueFormatterTest and is intended
'''to contain all DefaultValueFormatterTest Unit Tests
'''</summary>
<TestClass()> _
Public Class XmlValueFormatterTest

    Private testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = value
        End Set
    End Property

#Region "Additional test attributes"
    '
    'You can use the following additional attributes as you write your tests:
    '
    'Use ClassInitialize to run code before running the first test in the class
    '<ClassInitialize()>  _
    'Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    'End Sub
    '
    'Use ClassCleanup to run code after all tests in a class have run
    '<ClassCleanup()>  _
    'Public Shared Sub MyClassCleanup()
    'End Sub
    '
    'Use TestInitialize to run code before running each test
    '<TestInitialize()>  _
    'Public Sub MyTestInitialize()
    'End Sub
    '
    'Use TestCleanup to run code after each test has run
    '<TestCleanup()>  _
    'Public Sub MyTestCleanup()
    'End Sub
    '
#End Region

    '''<summary>
    '''A test for Serialize
    '''</summary>
    <TestMethod()> _
    Public Sub SerializeIntegerTest()
        Dim context As ISerializer = New XmlSerializer
        Dim graph As Integer = Environment.TickCount
        Dim type As Type = graph.GetType
        Dim target As IValueFormatter = New XmlValueFormatter(context, type)
        Dim expected As String = System.Xml.XmlConvert.ToString(graph)
        Dim actual As String
        actual = target.Serialize(graph)
        Assert.AreEqual(expected, actual)
    End Sub

    '''<summary>
    '''A test for Serialize
    '''</summary>
    <TestMethod()> _
    Public Sub SerializeDateTest()
        Dim context As ISerializer = New XmlSerializer
        Dim graph As Date = Date.Now
        Dim type As Type = graph.GetType
        Dim target As IValueFormatter = New XmlValueFormatter(context, type)
        Dim expected As String = System.Xml.XmlConvert.ToString(graph, System.Xml.XmlDateTimeSerializationMode.Utc)
        Dim actual As String
        actual = target.Serialize(graph)
        Assert.AreEqual(expected, actual)
    End Sub

    '''<summary>
    '''A test for Deserialize
    '''</summary>
    <TestMethod()> _
    Public Sub DeserializeDateTest()
        Dim context As ISerializer = New XmlSerializer
        ' The original object
        Dim graph As Date = Date.Now
        ' The original type
        Dim type As Type = graph.GetType

        Dim value As String = System.Xml.XmlConvert.ToString(graph, System.Xml.XmlDateTimeSerializationMode.Utc)
        Dim expected As Date = System.Xml.XmlConvert.ToDateTime(value, System.Xml.XmlDateTimeSerializationMode.Utc)
        Dim target As IValueFormatter = New XmlValueFormatter(context, type)

        Dim actual As Date
        actual = DirectCast(target.Deserialize(value), Date)
        Assert.AreEqual(expected, actual)
    End Sub

    '''<summary>
    '''A test for Deserialize
    '''</summary>
    <TestMethod()> _
    Public Sub DeserializeIntegerTest()
        Dim context As ISerializer = New XmlSerializer
        ' The original object
        Dim graph As Integer = Environment.TickCount
        ' The original type
        Dim type As Type = graph.GetType

        Dim value As String = System.Xml.XmlConvert.ToString(graph)
        Dim expected As Integer = System.Xml.XmlConvert.ToInt32(value)
        Dim target As IValueFormatter = New XmlValueFormatter(context, type)

        Dim actual As Integer
        actual = DirectCast(target.Deserialize(value), Integer)
        Assert.AreEqual(expected, actual)
    End Sub

    '''<summary>
    '''A test for DefaultValueFormatter Constructor
    '''</summary>
    <TestMethod()> _
    Public Sub DefaultValueFormatterConstructorTest()
        Dim context As ISerializer = New XmlSerializer
        Dim type As Type = GetType(Short)
        Dim target As XmlValueFormatter = New XmlValueFormatter(context, type)
        'Assert.AreEqual(target.ValueType, type)
    End Sub
End Class
